%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Plots Figures A.17, A.18, and A.19
%
% need to run Stata Code MainRun.do first       
%
% Cloyne, Dimsdale and Hürtgen (2024) 								
%	"Are Tax Cuts Contractionary at the Zero Lower Bound? Evidence from a Century of Data"  	  		
%																			
% James Cloyne, Nicholas Dimsdale and Patrick Hürtgen, 2024
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

clear all
close all
clc

OPTIONS.ShadedBands=1;

%%

f1  = fullfile('..\StataOutput\StateDep\Figure4\','DataIRF_S_realGDPToTax_smoothed_s_lnRealGDP_smoothed.xlsx');
f2  = fullfile('..\StataOutput\StateDep\FigureA18andA19\','DataIRF_S_realGDPToTax_raw_s_lnRealGDP_raw.xlsx');

IRFa = xlsread(f2);
IRFb = xlsread(f1);

xmin=0;
xmax=13;
stepsize=1;
Sdep=5;
OPTIONS.H=xmax;
IRFa=IRFa(1:xmax,:);
IRFb=IRFb(1:xmax,:);


r_color = 235;
b_color = 235;
g_color = 255;


myplot=figure(1);

if OPTIONS.ShadedBands==0
    lb68=plot(xmin:xmax-1,IRFa(:,3+Sdep), 'k:','LineWidth',1,'MarkerSize',5);hold on
    ub68=plot(xmin:xmax-1,IRFa(:,4+Sdep), 'k:','LineWidth',1,'MarkerSize',5);hold on
    lb95=plot(xmin:xmax-1,IRFa(:,5+Sdep), 'k--','LineWidth',1,'MarkerSize',5);hold on
    ub95=plot(xmin:xmax-1,IRFa(:,6+Sdep), 'k--','LineWidth',1,'MarkerSize',5);hold on
elseif OPTIONS.ShadedBands==1
    shadedplot(xmin:xmax-1,IRFa(:,3+Sdep)',IRFa(:,4+Sdep)',[r_color/255 b_color/255 g_color/255],[r_color/255 b_color/255 g_color/255]); hold on;
    plot(xmin:xmax-1,IRFa(:,5+Sdep),'b','MarkerSize',5); hold on;
    plot(xmin:xmax-1,IRFa(:,6+Sdep),'b','MarkerSize',5); hold on;
end

IRFx(1,:)=IRFa(:,2+Sdep);
IRFx(xmax-1,:)=IRFa(xmax-1,2+Sdep);
IRFx=IRFa(:,2+Sdep);
for ijk=2:xmax-1;
    IRFx(ijk,:)=1/3*(IRFa(ijk-1,2+Sdep)+IRFa(ijk,2+Sdep)+IRFa(ijk+1,2+Sdep));
end

a=plot(xmin:xmax-1,IRFa(:,2+Sdep), 'b-o','LineWidth',2.5,'MarkerSize',8);hold on
b=plot(xmin:xmax-1,IRFb(:,2+Sdep),  '--','color','#2f7e2b','LineWidth',2.5,'MarkerSize',5);hold on

plot([min(xlim()),max(xlim())],[0,0], 'k','LineWidth',0.25);
set(gca,'TickDir','in'); 

xlabel('Quarters')
box off; grid off
set(gca,'XLIM', [-inf inf], 'gridlinestyle', '-.', 'gridalpha', 0.5, 'FontSize',16)
set(gca,'XLIM', [xmin xmax-1]);
set(gca,'XTick',[xmin:stepsize:xmax-1]);
set(gca,'YLIM', [-2 8]);
yticks([-2 0 2 4 6 8])
myplot.PaperPositionMode = 'manual';
set(myplot,'Position',[50 50 1200 800]);
orient(myplot,'landscape')

saveas(myplot, 'FigureA18a', 'pdf')
saveas(myplot, 'FigureA18a', 'epsc')

%% Non-ZLB Regime 

f1  = fullfile('..\StataOutput\StateDep\Figure4\','DataIRF_S_realGDPToTax_smoothed_s_lnRealGDP_smoothed.xlsx');
f2  = fullfile('..\StataOutput\StateDep\FigureA18andA19\','DataIRF_S_realGDPToTax_raw_s_lnRealGDP_raw.xlsx');

IRFa = xlsread(f2);
IRFb = xlsread(f1);

xmin=0;
xmax=13;
stepsize=1;
Sdep=0;
OPTIONS.H=xmax;
IRFa=IRFa(1:xmax,:);
IRFb=IRFb(1:xmax,:);

myplot=figure(2);
if OPTIONS.ShadedBands==0
    lb68=plot(xmin:xmax-1,IRFa(:,3+Sdep), 'k:','LineWidth',1,'MarkerSize',5);hold on
    ub68=plot(xmin:xmax-1,IRFa(:,4+Sdep), 'k:','LineWidth',1,'MarkerSize',5);hold on
    lb95=plot(xmin:xmax-1,IRFa(:,5+Sdep), 'k--','LineWidth',1,'MarkerSize',5);hold on
    ub95=plot(xmin:xmax-1,IRFa(:,6+Sdep), 'k--','LineWidth',1,'MarkerSize',5);hold on
elseif OPTIONS.ShadedBands==1
    shadedplot(xmin:xmax-1,IRFa(:,3+Sdep)',IRFa(:,4+Sdep)',[r_color/255 b_color/255 g_color/255],[r_color/255 b_color/255 g_color/255]); hold on;
    plot(xmin:xmax-1,IRFa(:,5+Sdep),'b','MarkerSize',5); hold on;
    plot(xmin:xmax-1,IRFa(:,6+Sdep),'b','MarkerSize',5); hold on;
end

a=plot(xmin:xmax-1,IRFa(:,2+Sdep), 'b-o','LineWidth',2.5,'MarkerSize',8);hold on
b=plot(xmin:xmax-1,IRFb(:,2+Sdep),  '--','color','#2f7e2b','LineWidth',2.5,'MarkerSize',5);hold on

plot([min(xlim()),max(xlim())],[0,0], 'k','LineWidth',0.25);
set(gca,'TickDir','in'); 
xlabel('Quarters')
box off; grid off
set(gca,'XLIM', [-inf inf], 'gridlinestyle', '-.', 'gridalpha', 0.5, 'FontSize',16)
set(gca,'XLIM', [xmin xmax-1]);
set(gca,'XTick',[xmin:stepsize:xmax-1]);
yticks([-2 0 2 4 6 8])
myplot.PaperPositionMode = 'manual';
set(myplot,'Position',[50 50 1200 800]);
orient(myplot,'landscape')

saveas(myplot, 'FigureA19a', 'pdf')
saveas(myplot, 'FigureA19a', 'epsc')

%% Average effect on  GDP

f1  = fullfile('..\StataOutput\AE\Figure3\','DataIRF_LP_realGDPToTax_smoothed_s_Average_smoothed.xlsx');
f2  = fullfile('..\StataOutput\AE\FigureA17\','DataIRF_LP_realGDPToTax_raw_s_Average_raw.xlsx');

IRFa = xlsread(f1);
IRFb = xlsread(f2);

xmin=0;
xmax=13;
stepsize=1;
Sdep=0;
OPTIONS.H=xmax;

IRFa = xlsread(f2);
IRFb = xlsread(f1);

myplot=figure(3);

if OPTIONS.ShadedBands==0
    lb68=plot(xmin:xmax-1,IRFa(:,3+Sdep), 'k:','LineWidth',1,'MarkerSize',5);hold on
    ub68=plot(xmin:xmax-1,IRFa(:,4+Sdep), 'k:','LineWidth',1,'MarkerSize',5);hold on
    lb95=plot(xmin:xmax-1,IRFa(:,5+Sdep), 'k--','LineWidth',1,'MarkerSize',5);hold on
    ub95=plot(xmin:xmax-1,IRFa(:,6+Sdep), 'k--','LineWidth',1,'MarkerSize',5);hold on
elseif OPTIONS.ShadedBands==1
    shadedplot(xmin:xmax-1,IRFa(:,3+Sdep)',IRFa(:,4+Sdep)',[r_color/255 b_color/255 g_color/255],[r_color/255 b_color/255 g_color/255]); hold on;
    plot(xmin:xmax-1,IRFa(:,5+Sdep),'b','MarkerSize',5); hold on;
    plot(xmin:xmax-1,IRFa(:,6+Sdep),'b','MarkerSize',5); hold on;
end

a=plot(xmin:xmax-1,IRFa(:,2+Sdep), 'b-o','LineWidth',2.5,'MarkerSize',8);hold on
b=plot(xmin:xmax-1,IRFb(:,2+Sdep),  '--','color','#2f7e2b','LineWidth',2.5,'MarkerSize',5);hold on

plot([min(xlim()),max(xlim())],[0,0], 'k','LineWidth',0.25);
set(gca,'TickDir','in'); 

xlabel('Quarters')
box off; grid off
set(gca,'XLIM', [-inf inf], 'gridlinestyle', '-.', 'gridalpha', 0.5, 'FontSize',16)
set(gca,'XLIM', [xmin xmax-1]);
set(gca,'XTick',[xmin:stepsize:xmax-1]);
set(gca,'YLIM', [-2 6]);
yticks([-2 0 2 4 6 ])
myplot.PaperPositionMode = 'manual';
set(myplot,'Position',[50 50 1200 800]);
orient(myplot,'landscape')

saveas(myplot, 'FigureA17a', 'pdf');
saveas(myplot, 'FigureA17a', 'epsc');

%% ATR ZLB Regime 

f1  = fullfile('..\StataOutput\StateDep\Figure4\'  ,'DataIRF_S_ATRToTax_smoothed_s_ATR_smoothed.xlsx');
f2  = fullfile('..\StataOutput\StateDep\FigureA18andA19\','DataIRF_S_ATRToTax_raw_s_ATR_raw.xlsx');

IRFa = xlsread(f2);
IRFb = xlsread(f1);

xmin=0;
xmax=13;
stepsize=1;
Sdep=5
OPTIONS.H=xmax;
IRFa=IRFa(1:xmax,:);
IRFb=IRFb(1:xmax,:);

myplot=figure(4);

if OPTIONS.ShadedBands==0
    lb68=plot(xmin:xmax-1,IRFa(:,3+Sdep), 'k:','LineWidth',1,'MarkerSize',5);hold on
    ub68=plot(xmin:xmax-1,IRFa(:,4+Sdep), 'k:','LineWidth',1,'MarkerSize',5);hold on
    lb95=plot(xmin:xmax-1,IRFa(:,5+Sdep), 'k--','LineWidth',1,'MarkerSize',5);hold on
    ub95=plot(xmin:xmax-1,IRFa(:,6+Sdep), 'k--','LineWidth',1,'MarkerSize',5);hold on
elseif OPTIONS.ShadedBands==1
    shadedplot(xmin:xmax-1,IRFa(:,3+Sdep)',IRFa(:,4+Sdep)',[r_color/255 b_color/255 g_color/255],[r_color/255 b_color/255 g_color/255]); hold on;
    plot(xmin:xmax-1,IRFa(:,5+Sdep),'b','MarkerSize',5); hold on;
    plot(xmin:xmax-1,IRFa(:,6+Sdep),'b','MarkerSize',5); hold on;
end

a=plot(xmin:xmax-1,IRFa(:,2+Sdep), 'b-o','LineWidth',2.5,'MarkerSize',8);hold on
b=plot(xmin:xmax-1,IRFb(:,2+Sdep),  '--','color','#2f7e2b','LineWidth',2.5,'MarkerSize',5);hold on

plot([min(xlim()),max(xlim())],[0,0], 'k','LineWidth',0.25);
set(gca,'TickDir','in'); 

xlabel('Quarters')
box off; grid off
set(gca,'XLIM', [-inf inf], 'gridlinestyle', '-.', 'gridalpha', 0.5, 'FontSize',16)
set(gca,'XLIM', [xmin xmax-1]);
set(gca,'YLIM', [-7 1]);
set(gca,'XTick',[xmin:stepsize:xmax-1]);
set(gca,'YLIM', [-8 2]);
yticks([-8 -6 -4 -2 0  2])
myplot.PaperPositionMode = 'manual';
set(myplot,'Position',[50 50 1200 800]);
orient(myplot,'landscape')

saveas(myplot, 'FigureA18b', 'pdf')
saveas(myplot, 'FigureA18b', 'epsc')

%% ATR Non-ZLB Regime 

f1  = fullfile('..\StataOutput\StateDep\Figure4\'  ,'DataIRF_S_ATRToTax_smoothed_s_ATR_smoothed.xlsx');
f2  = fullfile('..\StataOutput\StateDep\FigureA18andA19\','DataIRF_S_ATRToTax_raw_s_ATR_raw.xlsx');

IRFa = xlsread(f2);
IRFb = xlsread(f1);

xmin=0;
xmax=13;
stepsize=1;
Sdep=0;
OPTIONS.H=xmax;
IRFa=IRFa(1:xmax,:);
IRFb=IRFb(1:xmax,:);

myplot=figure(5);if OPTIONS.ShadedBands==0
    lb68=plot(xmin:xmax-1,IRFa(:,3+Sdep), 'k:','LineWidth',1,'MarkerSize',5);hold on
    ub68=plot(xmin:xmax-1,IRFa(:,4+Sdep), 'k:','LineWidth',1,'MarkerSize',5);hold on
    lb95=plot(xmin:xmax-1,IRFa(:,5+Sdep), 'k--','LineWidth',1,'MarkerSize',5);hold on
    ub95=plot(xmin:xmax-1,IRFa(:,6+Sdep), 'k--','LineWidth',1,'MarkerSize',5);hold on
elseif OPTIONS.ShadedBands==1
    shadedplot(xmin:xmax-1,IRFa(:,3+Sdep)',IRFa(:,4+Sdep)',[r_color/255 b_color/255 g_color/255],[r_color/255 b_color/255 g_color/255]); hold on;
    plot(xmin:xmax-1,IRFa(:,5+Sdep),'b','MarkerSize',5); hold on;
    plot(xmin:xmax-1,IRFa(:,6+Sdep),'b','MarkerSize',5); hold on;
end

a=plot(xmin:xmax-1,IRFa(:,2+Sdep), 'b-o','LineWidth',2.5,'MarkerSize',8);hold on
b=plot(xmin:xmax-1,IRFb(:,2+Sdep),  '--','color','#2f7e2b','LineWidth',2.5,'MarkerSize',5);hold on

plot([min(xlim()),max(xlim())],[0,0], 'k','LineWidth',0.25);
set(gca,'TickDir','in');

xlabel('Quarters')
box off; grid off
set(gca,'XLIM', [-inf inf], 'gridlinestyle', '-.', 'gridalpha', 0.5, 'FontSize',16)
set(gca,'XLIM', [xmin xmax-1]);
set(gca,'YLIM', [-3 1]);
set(gca,'XTick',[xmin:stepsize:xmax-1]);
%yticks([-2 0 2 4 6 8])
yticks([-3 -2 -1 0  1])

myplot.PaperPositionMode = 'manual';
set(myplot,'Position',[50 50 1200 800]);
orient(myplot,'landscape')

saveas(myplot, 'FigureA19b', 'pdf')
saveas(myplot, 'FigureA19b', 'epsc')

%% Average effect on ATR

f1  = fullfile('..\StataOutput\AE\Figure3\'  ,'DataIRF_LP_ATRToTax_smoothed_s_Average_smoothed.xlsx');
f2  = fullfile('..\StataOutput\AE\FigureA17\','DataIRF_LP_ATRToTax_raw_s_Average_raw.xlsx');

IRFa = xlsread(f2);
IRFb = xlsread(f1);

xmin=0;
xmax=13;
stepsize=1;
Sdep=0;
OPTIONS.H=xmax;
IRFa=IRFa(1:xmax,:);
IRFb=IRFb(1:xmax,:);

myplot=figure(6);

if OPTIONS.ShadedBands==0
    lb68=plot(xmin:xmax-1,IRFa(:,3+Sdep), 'k:','LineWidth',1,'MarkerSize',5);hold on
    ub68=plot(xmin:xmax-1,IRFa(:,4+Sdep), 'k:','LineWidth',1,'MarkerSize',5);hold on
    lb95=plot(xmin:xmax-1,IRFa(:,5+Sdep), 'k--','LineWidth',1,'MarkerSize',5);hold on
    ub95=plot(xmin:xmax-1,IRFa(:,6+Sdep), 'k--','LineWidth',1,'MarkerSize',5);hold on
elseif OPTIONS.ShadedBands==1
    shadedplot(xmin:xmax-1,IRFa(:,3+Sdep)',IRFa(:,4+Sdep)',[r_color/255 b_color/255 g_color/255],[r_color/255 b_color/255 g_color/255]); hold on;
    plot(xmin:xmax-1,IRFa(:,5+Sdep),'b','MarkerSize',5); hold on;
    plot(xmin:xmax-1,IRFa(:,6+Sdep),'b','MarkerSize',5); hold on;
end

a=plot(xmin:xmax-1,IRFa(:,2+Sdep), 'b-o','LineWidth',2.5,'MarkerSize',8);hold on
b=plot(xmin:xmax-1,IRFb(:,2+Sdep),  '--','color','#2f7e2b','LineWidth',2.5,'MarkerSize',5);hold on

plot([min(xlim()),max(xlim())],[0,0], 'k','LineWidth',0.25);
set(gca,'TickDir','in'); 

xlabel('Quarters')
box off; grid off
set(gca,'XLIM', [-inf inf], 'gridlinestyle', '-.', 'gridalpha', 0.5, 'FontSize',16)
set(gca,'XLIM', [xmin xmax-1]);
set(gca,'XTick',[xmin:stepsize:xmax-1]);
set(gca,'YLIM', [-3 1]);
yticks([-3 -2 -1 0 1 ])
myplot.PaperPositionMode = 'manual';
set(myplot,'Position',[50 50 1200 800]);
orient(myplot,'landscape')

saveas(myplot, 'FigureA17b', 'pdf')
saveas(myplot, 'FigureA17b', 'epsc')



